<?php

namespace app\api\controller;

class Base
{

    //注册功能
    public function register()
    {
        $no = input('get.no');
        $password = input('get.password');
        $name = input('get.name');
        if (empty($no)) output_error('手机号不能为空');
        if (empty($password)) output_error('密码不能为空');
        if (empty($name)) output_error('昵称不能为空');
        $data = Student::where('student_no', '=', $no)->find();
        if (!empty($data))output_error('已注册');
        $data = array();
        $data['student_no'] = $no;
        $data['student_name'] = $name;
        $data['student_password'] = md5($password);
        $data['student_token'] = '1';
        $data['student_gender'] = '1';
        $data['add_time'] = time();
        Student::insert($data);
        output_data('1');
        //传入学号，姓名，密码注册
        //规则1：学号唯一
        //规则2：密码md5加密
    }

    //找回密码


    public function findpass()
    {
        $no = input('get.no');
        $name = input('get.name');
        $password = input('get.password');
        if (empty($no)||empty($password)||empty($name)){
            output_error('填完信息');
        }
        $condition = array();
        $condition[]=['student_no','='.$no];
        $condition[]=['student_name','='.$name];
        $data = Student::where($condition)->find();
        if (empty($data))output_error('不匹配');
        Student::where('student_id','=',$data['studen_id'])
            ->updata(array('student_password'=>md5($password)));
        output_data('1');
        //通过学号，姓名重置密码
        //规则1：密码md5加密
    }

    //登录功能

        public function login()
    {
        $no = input('get.no');
        $password = input('get.password');
        if (empty($no)||empty($password)){
            output_error('填完信息');
        }
        $condition = array();
        $condition[]=['student_no','='.$no];
        $condition[]=['student_password','=',md5($password)];
        $data = Student::where($condition)->find();
        if (empty($data))output_error('不匹配');
        $token =md5($no . time());
        Student::where('student_id','=',$data['student_id'])
            ->updata(array('student_token'=>$token));
        output_data($token);
        //通过学号，密码登录，返回Token
        //规则1：token由学号+当前时间戳md5加密生成


}
